package com.aaa.controller;

import com.aaa.dao.SysBankDao;
import com.aaa.pojo.BankNumber;
import com.aaa.pojo.BankType;
import com.aaa.pojo.SysBank;
import com.aaa.service.BankNumberService;
import com.aaa.service.BankTypeService;
import com.aaa.service.SysBankService;
import com.aaa.tool.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
public class BankNumberController {
    //银行卡号
    @Autowired
    private BankNumberService service;
    //银行
    @Autowired
    private SysBankService sysBankService;
    //银行卡类型
    @Autowired
    private BankTypeService typeService;
    //查询所有银行卡
    @RequestMapping("/bank")
    public Result queryBankNumber(HttpServletRequest request){
        HttpSession session = request.getSession();
        Integer uid = (Integer) session.getAttribute("uid");
        List<BankNumber> bankNumbers = service.queryBankNumberAll(uid);
       return Result.ok(bankNumbers);
    }

    @RequestMapping("/bank2")
    public Result SysBank(){
        List<SysBank> sysBanks = sysBankService.selAllBank();
        return Result.ok(sysBanks);
    }
    @RequestMapping("/bank3")
    public Result BankType(){
         List<BankType> bankTypes = typeService.selBankType();
        return Result.ok(bankTypes);
    }

    @RequestMapping("/showUpdate")
    public Result selByBankID(Integer bank_id){
        BankNumber bankNumber = service.selByBankID(bank_id);
        return Result.ok(bankNumber);
    }


    @RequestMapping("/update")
    public Result updByBankID(Integer bank_id,String bank_card,Integer b_id,Integer tid){
        service.updByBankID(bank_id,bank_card,b_id,tid);
        return Result.ok();
    }


    @RequestMapping(name = "添加银行卡",value = "/insert")
    @ResponseBody
    public Result addBankNumber(String bank_card,Integer b_id,Integer tid,HttpServletRequest request){
        HttpSession session = request.getSession();
        Integer uid = (Integer) session.getAttribute("uid");
        Boolean number = service.addBankNumber(bank_card,b_id,tid,uid);
        System.out.println(bank_card);
        return Result.ok();
    }

    @RequestMapping("/del")
    public Result delBankNumber(Integer bank_id){
        Boolean del = service.delByBankID(bank_id);
        return Result.ok();
    }
}
